class Singleton:

    __instance = None
    __counter = 0

    class __impl:

        def __init__(self):
            print "Running __impl init"

        def spam(self):
            return id(self)

    def __init__(self):
        Singleton.__counter += 1
        if Singleton.__instance == None:
           Singleton.__instance = Singleton.__impl()
        else:
            print "Instance = ", Singleton.__instance

        print self.__dict__

    def __getattr__(self, attr):
        print attr
        return getattr(self.__instance, attr)

    def __setattr__(self, attr, value):
        return setattr(self.__instance, attr, value)

y = Singleton()
print "id(y) =", id(y)
print y.spam()
print
print
x = Singleton()
print x.spam()
